import java.util.Stack;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-03-03
 * Time: 19:33
 */
class Solution1 {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String val = tokens[i];
            if (!isOperation(val)) {
                //如果不是运算符
                stack.push(Integer.parseInt(val));
            } else {
                //如果是运算符
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (val) {
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }
            }
        }
        return stack.pop();
    }
    private boolean isOperation(String x) {
        if (x.equals("+") || x.equals("-") || x.equals("*") || x.equals("/")) {
            return true;
        }
        return false;
    }
}
class Solution {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer>stack = new Stack<>();
        for (int i = 0; i < pushed.length; i++) {
            String val1 = String.valueOf(pushed[i]);
        }
        return false;
    }
}

public class TestDemo {
    public static void main3(String[] args) {

    }
    public static void main2(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(2);
        stack.push(3);
        System.out.println(stack.size());
    }
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        System.out.println(stack.empty());//true 即stack栈中元素为空
        stack.push(7);
        stack.push(42);
        stack.push(12);
        stack.push(277);
        stack.push(132);
        System.out.println(stack.size());//5 栈中元素为5个
        System.out.println(stack.peek());//132 获取栈顶元素132 但是不删除
        System.out.println(stack.pop());//132 弹出栈顶元素132 并删除
        System.out.println(stack.size());//4 此时栈中元素为4个
        System.out.println(stack.empty());//false 此时栈中元素不为空
        System.out.println(stack.pop());//277 弹出栈顶元素277 并删除
        System.out.println(stack.peek());//12 获取栈顶元素12 但是不删除
    }

}
